<template>
  <el-dialog :visible.sync="editVisible" title="分组设置" width="500px">
    <el-form :model="deployGroup" label-width="80px" size="mini" style="width: 400px;">
      <el-form-item label="分组名称">
        <el-input v-model="deployGroup.name" :disabled="deployGroup.id!=null"/>
      </el-form-item>
      <el-form-item label="展示名称">
        <el-input v-model="deployGroup.showName"></el-input>
      </el-form-item>
      <el-form-item label="环境类型">
        <el-select v-model="deployGroup.envType" style="width: 100%">
          <el-option v-for="envType in envTypes" :key="envType.code" :label="envType.name" :value="envType"/>
        </el-select>
      </el-form-item>
      <el-form-item label="代码分支">
        <el-input v-model="deployGroup.gitBranch"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="saveDeployGroup(appInfo)">保存</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>
<script>
import {saveDeployGroupApi} from "@/api/manage";
import {enumsApi} from "@/api/common";

export default {
  data() {
    return {
      editVisible: false,
      appInfo: {},
      deployGroup: {},
      envTypes: [],
    };
  },
  methods: {
    openEdit(appInfo, deployGroup) {
      this.appInfo = appInfo;
      this.deployGroup = deployGroup;
      this.editVisible = true;
    },
    async saveDeployGroup() {
      let data = Object.assign({}, this.deployGroup);
      data.appName = this.appInfo.appName;
      data.envType = this.deployGroup.envType.code;
      await saveDeployGroupApi(data);
      this.$message({message: `保存成功`, type: "success",});
      this.$emit("saveSuccess");
      this.editVisible = false;
    },
  },
  async created() {
    this.envTypes = await enumsApi("EnvType");
  },
};
</script>